package com.sm.honkon.app.utils;


public class HexUtils {

    public static String u8(long v) {
        char[] var2 = new char[16];

        for(int var3 = 0; var3 < 16; ++var3) {
            var2[15 - var3] = Character.forDigit((int)v & 15, 16);
            v >>= 4;
        }

        return new String(var2);
    }

    public static String u4(int v) {
        char[] var1 = new char[8];

        for(int var2 = 0; var2 < 8; ++var2) {
            var1[7 - var2] = Character.forDigit(v & 15, 16);
            v >>= 4;
        }

        return new String(var1);
    }

    public static String u3(int v) {
        char[] var1 = new char[6];

        for(int var2 = 0; var2 < 6; ++var2) {
            var1[5 - var2] = Character.forDigit(v & 15, 16);
            v >>= 4;
        }

        return new String(var1);
    }

    public static String u2(int v) {
        char[] var1 = new char[4];

        for(int var2 = 0; var2 < 4; ++var2) {
            var1[3 - var2] = Character.forDigit(v & 15, 16);
            v >>= 4;
        }

        return new String(var1);
    }

    public static String u2or4(int v) {
        return v == (char)v ? u2(v) : u4(v);
    }

    public static String u1(int v) {
        char[] var1 = new char[2];

        for(int var2 = 0; var2 < 2; ++var2) {
            var1[1 - var2] = Character.forDigit(v & 15, 16);
            v >>= 4;
        }

        return new String(var1);
    }

    public static String uNibble(int v) {
        char[] var1 = new char[]{Character.forDigit(v & 15, 16)};
        return new String(var1);
    }

    public static String s8(long v) {
        char[] var2 = new char[17];
        if (v < 0L) {
            var2[0] = '-';
            v = -v;
        } else {
            var2[0] = '+';
        }

        for(int var3 = 0; var3 < 16; ++var3) {
            var2[16 - var3] = Character.forDigit((int)v & 15, 16);
            v >>= 4;
        }

        return new String(var2);
    }

    public static String s4(int v) {
        char[] var1 = new char[9];
        if (v < 0) {
            var1[0] = '-';
            v = -v;
        } else {
            var1[0] = '+';
        }

        for(int var2 = 0; var2 < 8; ++var2) {
            var1[8 - var2] = Character.forDigit(v & 15, 16);
            v >>= 4;
        }

        return new String(var1);
    }

    public static String s2(int v) {
        char[] var1 = new char[5];
        if (v < 0) {
            var1[0] = '-';
            v = -v;
        } else {
            var1[0] = '+';
        }

        for(int var2 = 0; var2 < 4; ++var2) {
            var1[4 - var2] = Character.forDigit(v & 15, 16);
            v >>= 4;
        }

        return new String(var1);
    }

    public static String s1(int v) {
        char[] var1 = new char[3];
        if (v < 0) {
            var1[0] = '-';
            v = -v;
        } else {
            var1[0] = '+';
        }

        for(int var2 = 0; var2 < 2; ++var2) {
            var1[2 - var2] = Character.forDigit(v & 15, 16);
            v >>= 4;
        }

        return new String(var1);
    }

    public static String dump(byte[] arr, int offset, int length, int outOffset, int bpl, int addressLength) {
        int var6 = offset + length;
        if ((offset | length | var6) >= 0 && var6 <= arr.length) {
            if (outOffset < 0) {
                throw new IllegalArgumentException("outOffset < 0");
            } else if (length == 0) {
                return "";
            } else {
                StringBuffer var7 = new StringBuffer(length * 4 + 6);

                int var8;
                for(var8 = 0; length > 0; --length) {
                    if (var8 == 0) {
                        String var9;
                        switch(addressLength) {
                            case 2:
                                var9 = u1(outOffset);
                                break;
                            case 3:
                            case 5:
                            default:
                                var9 = u4(outOffset);
                                break;
                            case 4:
                                var9 = u2(outOffset);
                                break;
                            case 6:
                                var9 = u3(outOffset);
                        }

                        var7.append(var9);
                        var7.append(": ");
                    } else if ((var8 & 1) == 0) {
                        var7.append(' ');
                    }

                    var7.append(u1(arr[offset]));
                    ++outOffset;
                    ++offset;
                    ++var8;
                    if (var8 == bpl) {
                        var7.append('\n');
                        var8 = 0;
                    }
                }

                if (var8 != 0) {
                    var7.append('\n');
                }

                return var7.toString();
            }
        } else {
            throw new IndexOutOfBoundsException("arr.length " + arr.length + "; " + offset + "..!" + var6);
        }
    }

    public static String toHexString(byte[] ubytes,int size) {
        StringBuilder var1 = new StringBuilder(size << 1);
        byte[] var2 = ubytes;
        int var3 = size;

        for(int var4 = 0; var4 < var3; ++var4) {
            byte var5 = var2[var4];
            var1.append(u1(var5));
        }

        return var1.toString();
    }
}